package com.library.Mapper;

import com.library.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 增加分类下的书
     * @param category
     */
    @Update("update category set book_number = book_number+1  where name=#{category}")
    void update(String category);

    /**
     * 减少分类下的书
     * @param category
     */
    @Update("update category set book_number = book_number-1 where name=#{category}")
    void deleteNumber(String category);

    /**
     * 查询所有分类的名称
     * @return
     */
    List<Category> getType(@Param("name")String name);

    /**
     * 根据id查询
     * @param id
     * @return
     */
@Select("select * from category where id=#{id}")
    Category getById(@Param("id") Long id);

    /**
     * 新增分类
     * @param category
     */
    @Insert("insert into category (name,book_number,create_time,update_time) values (#{name},#{bookNumber},#{createTime},#{updateTime})")
    void add(Category category);
@Delete("delete from category where id=#{id}")
    void delete(@Param("id") Long id);
}
